package me.heyclock.hl.recordwriter.ui;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.heyclock.hl.recordwriter.R;

/**
 * Created by hl on 2018/3/19.
 */

/**
 * 分享底部弹窗
 */
public class ImageDIalog extends Dialog implements View.OnClickListener {
    private OnClickback callback;
    @BindView(R.id.image_cancel_btn)
    public Button cancel_btn;
    @BindView(R.id.image_screenshot)
    public TextView screenshot;
    @BindView(R.id.image_camerar)
    public TextView camerar;

    public static final  int screenShoot = 110;
    public static final  int cameraShoot = 111;
    public static final  int picturecrop = 112;

    public ImageDIalog(Context context, OnClickback callback) {
        this(context, R.layout.image_dialog, R.style.common_dialog,
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        this.callback = callback;
    }

    public ImageDIalog(final Context context, int layout, int style, int width,
                       int height) {
        super(context, style);
        setContentView(layout);
        ///< 注解绑定
        ButterKnife.bind(this);
        ///< 点击外部不消失
        setCanceledOnTouchOutside(false);
        ///< 设置属性值
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = width;
        lp.height = height;
        getWindow().setAttributes(lp);
        ///< 设置按钮监听事件
        setListener();
    }

    /**
     * 设置点击事件
     */
    private void setListener() {
        cancel_btn.setOnClickListener(this);
        screenshot.setOnClickListener(this);
        camerar.setOnClickListener(this);
    }

    @Override
    public void show() {
        super.show();
		///< 设置dialog显示动画
        getWindow().setWindowAnimations(R.style.dialogWindowAnimbottom);
        ///< 设置显示位置为底部
        getWindow().setGravity(Gravity.BOTTOM);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.image_screenshot:
                callback.onImage(screenShoot);
                dismiss();
                break;
            case R.id.image_camerar:
                callback.onImage(cameraShoot);
                dismiss();
                break;
            case R.id.image_cancel_btn:
                dismiss();
                break;
        }
    }

    /**
     * 点击分享回调接口
     */
    public interface OnClickback {
        abstract void onImage(int id);
    }
}
